package com.leyou.item.controller;

import com.leyou.common.enums.ExceptionEnum;
import com.leyou.common.exceptions.LyException;
import com.leyou.item.pojo.Item;
import com.leyou.item.service.port.IItemService;
import net.bytebuddy.implementation.bytecode.Throw;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ItemController {

    @Autowired
    private IItemService itemService;

    @PostMapping("item")
    public ResponseEntity<Item> saveItem(Item item){

        if (item.getPrice()==null){
           throw new LyException(ExceptionEnum.PRICE_CAN_OT_BE_NULL);
        }

        Item result = itemService.saveItem(item);
        return ResponseEntity.ok().body(result);
    }



}
